package com.netease.pris.activity;

import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.netease.framework.ActivityEx;
import com.netease.framework.d;
import com.netease.framework.f;
import com.netease.framework.k;
import com.netease.framework.l;
import com.netease.pris.app.PrisApp;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SetSkinActivity extends ActivityEx
{
  public static int a = 0;
  public static int b = 0;
  public static int c = 0;
  public static int d = 0;
  public static int e = 0;
  public static final String f = "set_skin_activity";
  private static final String h = "SetSkinActivity";
  private static final String i = "/download/";
  public Runnable g = new eb(this);
  private ListView j;
  private dm k;
  private List l;
  private c m;
  private Uri n;
  private IntentFilter o;
  private String p;
  private k q;
  private bx r = new bx(this, null);

  private void a(l paraml)
  {
    Object localObject = null;
    if ((paraml == null) || (this.p.equals(paraml.b())) || (TextUtils.isEmpty(paraml.b())))
    {
      String str1 = this.p;
      if (paraml != null)
        paraml.b(this.p);
      k.a(this).a(paraml);
      k.a(this).a(null);
      localObject = str1;
    }
    while (true)
    {
      if (localObject != null)
        PrisApp.a().a((String)localObject);
      return;
      if (paraml.b().matches("internal\\.skin\\..*"))
      {
        localObject = paraml.b();
        k.a(this).a(paraml);
        d locald = new d(getApplicationContext());
        k.a(this).a(locald);
        continue;
      }
      if (!paraml.b().matches("pris\\.skin\\..*"))
        continue;
      String str2 = paraml.b();
      k.a(this).a(paraml);
      try
      {
        localf = new f(getApplicationContext(), str2);
        localObject = str2;
        k.a(this).a(localf);
      }
      catch (PackageManager.NameNotFoundException localNameNotFoundException)
      {
        while (true)
        {
          localNameNotFoundException.printStackTrace();
          localObject = this.p;
          f localf = null;
        }
      }
    }
  }

  private void a(String paramString)
  {
    if (TextUtils.isEmpty(paramString));
    while (true)
    {
      return;
      if (!new File(paramString).exists())
      {
        Toast.makeText(this, "selecte skin package does not exist.", 0).show();
        f();
        continue;
      }
      Uri localUri = Uri.parse("file://" + paramString);
      Intent localIntent = new Intent("android.intent.action.VIEW", localUri);
      localIntent.setDataAndType(localUri, "application/vnd.android.package-archive");
      localIntent.setClassName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity");
      startActivity(localIntent);
    }
  }

  private void a(List paramList)
  {
    if (paramList == null)
      paramList = new ArrayList();
    l locall1 = this.q.f();
    if (locall1 == null);
    while (true)
    {
      Iterator localIterator = getPackageManager().getInstalledPackages(8192).iterator();
      while (localIterator.hasNext())
      {
        PackageInfo localPackageInfo = (PackageInfo)localIterator.next();
        if (!localPackageInfo.packageName.matches("pris\\.skin\\..*"))
          continue;
        l locall2 = this.q.a(localPackageInfo.packageName);
        if (locall2 == null)
          continue;
        paramList.add(locall2);
      }
      paramList.add(locall1);
    }
  }

  private void a(List paramList, String paramString)
  {
    if (!Environment.getExternalStorageState().equals("mounted"));
    File[] arrayOfFile;
    do
    {
      do
        return;
      while ((TextUtils.isEmpty(paramString)) || (paramList == null));
      arrayOfFile = new File(paramString).listFiles();
    }
    while (arrayOfFile == null);
    PackageManager localPackageManager = getPackageManager();
    int i1 = arrayOfFile.length;
    int i2 = 0;
    label53: File localFile;
    PackageInfo localPackageInfo;
    if (i2 < i1)
    {
      localFile = arrayOfFile[i2];
      if ((localFile.isFile()) && (localFile.getName().trim().endsWith(".apk")))
      {
        localPackageInfo = localPackageManager.getPackageArchiveInfo(paramString + localFile.getName().trim(), 0);
        if (localPackageInfo != null)
          break label135;
      }
    }
    while (true)
    {
      i2++;
      break label53;
      break;
      label135: if (!localPackageInfo.applicationInfo.packageName.matches("pris\\.skin\\..*"))
        continue;
      l locall = this.q.a(paramString + localFile.getName().trim(), localPackageManager, localPackageInfo, false);
      if ((locall == null) || (!a(paramList, locall)))
        continue;
      paramList.add(locall);
    }
  }

  private boolean a(List paramList, l paraml)
  {
    int i1;
    if ((paramList == null) || (paraml == null))
      i1 = 0;
    while (true)
    {
      return i1;
      Iterator localIterator = paramList.iterator();
      while (true)
        if (localIterator.hasNext())
        {
          l locall = (l)localIterator.next();
          if ((!locall.b().trim().equals(paraml.b().trim())) || (locall.d().trim().compareToIgnoreCase(paraml.d().trim()) < 0))
            continue;
          i1 = 0;
          break;
        }
      i1 = 1;
    }
  }

  private void b()
  {
    this.m = new c(this);
    this.l = new ArrayList();
    this.k = new dm(this, this, 2130903053, this.l);
    this.j.setAdapter(this.k);
  }

  private void b(l paraml)
  {
    if (paraml == null);
    while (true)
    {
      return;
      a(paraml);
      f();
    }
  }

  private void c()
  {
    this.j = ((ListView)findViewById(16908298));
    this.j.setOnItemClickListener(this.r);
  }

  private void e()
  {
    ((LinearLayout)findViewById(2131558483));
  }

  private void f()
  {
    this.l.clear();
    a(this.l);
    a(this.l, Environment.getExternalStorageDirectory() + "/download/");
    this.l.add(PrisApp.a().B());
    this.l.add(new l());
    this.k.notifyDataSetChanged();
  }

  public void f_()
  {
    e();
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903065);
    c();
    b();
    e();
    this.o = new IntentFilter();
    this.o.addAction("android.intent.action.PACKAGE_ADDED");
    this.o.addAction("android.intent.action.PACKAGE_REMOVED");
    this.o.addDataScheme("package");
    this.p = getPackageName();
    this.q = k.a(this);
  }

  public void onPause()
  {
    super.onPause();
    unregisterReceiver(this.m);
  }

  public void onResume()
  {
    super.onResume();
    f();
    registerReceiver(this.m, this.o);
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.pris.activity.SetSkinActivity
 * JD-Core Version:    0.6.0
 */